<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>WPSID Manager</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 20px;
            background-color: #1e1e1e; /* 调暗背景颜色 */
            color: #ffffff; /* 文本颜色 */
        }

        .container {
            max-width: 600px;
            margin: 0 auto;
            background-color: #2c2c2c; /* 调暗容器背景颜色 */
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.5); /* 调整阴影效果 */
        }

        .header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
        }

        .header span {
            font-size: 1.5em;
            font-weight: bold;
            color: #ffffff; /* 文本颜色 */
        }

        .header button {
            background-color: #4CAF50;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 4px;
            cursor: pointer;
            transition: background-color 0.3s;
        }

        .header button:hover {
            background-color: #45a049;
        }

        .path-row {
            display: flex;
            align-items: center;
            margin-bottom: 10px;
        }

        .path-row label {
            margin-right: 10px;
            color: #ffffff; /* 文本颜色 */
        }

        .path-row input {
            flex-grow: 1;
            padding: 8px;
            border: 1px solid #444444; /* 调整边框颜色 */
            border-radius: 4px;
            background-color: #333333; /* 调整输入框背景颜色 */
            color: #ffffff; /* 输入框文本颜色 */
            transition: border-color 0.3s;
        }

        .path-row input:focus {
            border-color: #4CAF50;
            outline: none;
        }

        .path-row button {
            margin-left: 10px;
            background-color: #f44336;
            color: white;
            border: none;
            padding: 8px 12px;
            border-radius: 4px;
            cursor: pointer;
            transition: background-color 0.3s;
        }

        .path-row button:hover {
            background-color: #d32f2f;
        }
    </style>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>

<body>
    <div class="container">
        <div class="header">
            <span>WPS表格ID</span>
            <button onclick="addNewItem()">+</button>
        </div>
        <div id="VirtualPath"></div>
    </div>
    <script>
        const vscode = acquireVsCodeApi();

        function addNewItem() {
            vscode.postMessage({ command: 'addNewItem' });
        }

        function updatePaths() {
            const paths = [];
            $('.path-row input').each(function () {
                paths.push($(this).val());
            });
            const jsonPaths = JSON.stringify(paths);
            vscode.postMessage({ command: 'Update', data: jsonPaths });
        }

        function deletePathRow(row) {
            $(row).remove();
            updatePaths();
        }

        window.addEventListener('message', event => {
            switch (event.data.type) {
                case 'addNewItem':
                    const newRow = `
                        <div class="path-row">
                            <label>表格ID:</label>
                            <input type="text" value="${event.data.data}" placeholder="请输入ID" style="width:400px">
                            <button class="delete" onclick="deletePathRow(this.parentNode)">删除</button>
                        </div>
                    `;
                    $('#VirtualPath').append(newRow);

                    // 使用事件委托，将事件监听器绑定到 #VirtualPath 上
                    $('#VirtualPath').off('input', '.path-row input').on('input', '.path-row input', updatePaths);
                    updatePaths();
                    break;
            }
        });
    </script>
</body>

</html>